package bsh.dyn;

/**
 * Contains utility methods
 * 
 * @author takeshi
 */
public final class Invocables {

    /**
     * ctor
     */
    private Invocables() {
    }

    /**
     * Adapts a java type to a {@link DeclaredParameterType}
     * 
     * @param type Class
     * @return {@link DeclaredParameterType}
     */
    public static DeclaredParameterType toDeclaredParameter(Class<?> type) {
        if (type.isPrimitive()) {
            return new PrimitiveParameter(type);
        } else {
            return new ReferenceDeclaredType(type);
        }
    }

    /**
     * Adapts an array of types to their {@link DeclaredParameterType}
     * 
     * @param types array of types
     * @return array of {@link DeclaredParameterType}
     */
    public static DeclaredParameterType[] toDeclaredParameters(Class<?>... types) {
        DeclaredParameterType[] declared = new DeclaredParameterType[types.length];
        for (int i = 0; i < types.length; i++) {
            declared[i] = toDeclaredParameter(types[i]);
        }
        return declared;
    }

}
